﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.BLL;
using Yipusoft.Exercitation.BLL;
using Yipusoft.Exercitation.Model;
using System.Drawing;

public partial class Combat_BaseItemList : System.Web.UI.Page
{
    string id = "55f5139f-489a-487d-8d55-ff6e555c7fda";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
            ListPageContral1.SetFirstPage();
            BindItemList(0);
        }
    }

    private void Bind()
    {
        ddlItemType.DataSource= ItemSkill.GetList(" ParentID='"+id+"'");
        ddlItemType.DataTextField = "ItemSkillName";
        ddlItemType.DataValueField = "ID";
        ddlItemType.DataBind();
    }
    protected void gvItemList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = ((ListPageContral1.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }

    private void BindItemList(int pageIndex)
    {
        if (string.IsNullOrEmpty(ddlItemType.SelectedValue))
            return;
        int count = ItemSkill.GetCount("1=1");
        ListPageContral1.ItemCount = count;
        gvItemList.DataSource= ItemSkill.GetList("ID", "ASC", "ParentID='"+ddlItemType.SelectedValue+"'", ListPageContral1.PageSize, pageIndex);
        gvItemList.DataBind();
    }

    public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        BindItemList(PageIndex);
    }
    protected void lnbtnQuery_Click(object sender, EventArgs e)
    {
        lblPrompt.Text = "";
        ListPageContral1.SetFirstPage();
        BindItemList(0);
    }
    protected void lnbtnDelete_Command(object sender, CommandEventArgs e)
    {
        int count= BaseSkill.GetCount(" ItemSkillID='"+e.CommandArgument.ToString()+"'");
        if (count<=0)
        {
            ItemSkill.Delete(new Guid(e.CommandArgument.ToString()));
            lnbtnQuery_Click(null, null);
        }
        else
        {
            lblPrompt.Text = "删除失败！请先删除对应关系";
            return;
            
        }
    }
}
